package zouran.service.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zouran.entity.User;
import zouran.mapper.AdminMapper;
import zouran.mapper.UserMapper;
import zouran.service.AdminService;
import java.util.List;
import java.util.Objects;
/**
 * @Author: zouran
 * @Description:
 * @Date: Created in 2022 2022/12/3 16:30
 **/
@Service
public class AdminServiceImpl implements AdminService {
    private AdminMapper adminMapper;
    private UserMapper userMapper;
    @Autowired
    public void setAdminMapper(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }
    @Autowired
    public void setUserMapper(UserMapper userMapper) {this.userMapper = userMapper;}
    @Override
    public int judge_admin(String Phone,String Password)
    {
        if(adminMapper.selectById(Phone)!=null)
            if(Objects.equals(adminMapper.selectById(Phone).getAdminPassword(), Password))
               return 1;
                   return 0;
    }
    @Override
    public List<User> getAllUser()
    {
        return userMapper.selectList(null);
    }
    @Override
    public boolean insert_user(User user){
        System.out.println(userMapper.insert(user));
        return true;
    }
    @Override
    public boolean delete_user(User user){
        return userMapper.deleteById(user.getUserPhone())==1;
    }
    @Override
    public boolean update_user(User user)
    {
        return userMapper.updateById(user) == 1;
    }
    @Override
    public List<User> select_user(String Phone){
        QueryWrapper<User> wq=new QueryWrapper<>() ;
        return userMapper.selectList(wq.eq("userPhone",Phone));
    }
}
